# 1 "main.c"
# 1 "/home/diego/sodium/kernel//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "main.c"
# 1 "../include/video.h" 1
# 13 "../include/video.h"
# 1 "../include/kernel/definiciones.h" 1
# 14 "../include/kernel/definiciones.h"
# 1 "../include/usr/tipos.h" 1
# 15 "../include/usr/tipos.h"
typedef unsigned int dword;
typedef unsigned short word;
typedef unsigned char byte;

typedef unsigned char u8;
typedef signed char s8;
typedef unsigned short u16;
typedef signed short s16;
typedef unsigned int u32;
typedef signed int s32;


typedef struct _u80 { unsigned int word[20]; } u80;
# 15 "../include/kernel/definiciones.h" 2
# 62 "../include/kernel/definiciones.h"
char stArgAux[128];
# 14 "../include/video.h" 2
# 1 "../include/kernel/libk/string.h" 1
# 9 "../include/kernel/libk/string.h"
inline unsigned char* ucpFnCopiarMemoria(unsigned char *ucpDestino,
      unsigned char *ucpOrigen,
      unsigned int uiTamanio);
inline unsigned char* ucpFnMemSetCero(unsigned char *ucpDirInicio,
                  unsigned int uiTamanio );

int iFnLongitudCadena (const char *cnstCadena);
int iFnCompararCadenas (const char *, const char *);
int iFnCompararCadenas2 (const char *, const char *);
int iFnCopiaCaracter (char *, const char *);
int iFnCopiaCadena (char *, const char *);

int iFnCopiaEntero (char *, const int);
int iFnCopiaFloat (char *, const float, const int);
int iFnCopiaWord (char *, const word);
int iFnCopiaByte (char *, const byte);
int iFnCopiaHexa (char *, const int);
int iFnCopiaWordHexa (char *, const word);
int iFnCopiaByteHexa (char *, const byte);
void vFnImprimirString (char *, const char *, ...);
int iFnLongitudCadena (const char *);

int iFnCopiaCadena2 (char *, const char *);
char * pstFnConcatenarCadena (char * , char * );
int iFnBuscarEnCadena (char * , char * ,int );
char * pstFnCadenaIzquierda (char * , int );
char * pstFnCadenaDerecha (char * , int );
int iFnEsNumero (char * stCadena);

void vFnStrLwr (char * stCadena);
void vFnStrUpr (char * stCadena);
# 15 "../include/video.h" 2
# 58 "../include/video.h"
typedef char* va_list;
# 100 "../include/video.h"
int iFnImprimirCadenas (int,const char*);




void vFnImprimirEntero (int,const int);




void vFnImprimirFloat (int,const double, const int);




void vFnImprimirHexa (int,const int);




void vFnImprimirWordHexa (int,const word);




void vFnImprimirByteHexa (int,const byte);





void vFnImprimirWin (int,const char*, ... );
void vFnImprimir (const char*, ... );
void vFnImprimirI (const char*, ... );

extern char cFnSysObtenerColor(int);
extern void vFnSysSetearColor(int,char);
extern void vFnSysSetearX(int,int);
extern void vFnSysSetearY(int,int);
extern void vFnClsWin(int);





void vFnImprimirContextSwitch(int color,int pid, char* nombre, int indiceGDT);
void vFnImprimirPrompt();
void vFnImprimirOk(int linea);
void vFnImprimirNOk(int linea);

void vFnImprimirVentana (int hVentana, const char *cnstCadena, ...);






int bTerminalActiva;

void vFnCambiarTerminal(void);
void vFnLog (const char *cnstCadena, ...);

void vFnLogScrollArriba();
void vFnLogScrollAbajo();

void vFnLogScrollMaximo();
void vFnLogScrollMinimo();
void vFnLogBorrar();
# 2 "main.c" 2
# 1 "../include/kernel/pcb.h" 1







# 1 "../include/kernel/shm.h" 1
# 18 "../include/kernel/shm.h"
typedef unsigned int size_t;
typedef int key_t;
typedef int bool;


typedef struct _stuMemoriasAtachadas_
{
 bool utilizada;
 int posicionEnShMem;
 int posicionEnAttach;
}stuMemoriasAtachadas;


typedef struct _attach_
{
 int pid;
 void * ptrShAddr;

}attach;


typedef struct _shMem_
{
 key_t key;
 unsigned long int tamanio;
 attach procAtt[5];
 bool declarada;
}shMem;

shMem memoriasCompartidas[5];




int iFnShmGet(key_t key, size_t size);


int iFnShmAt(int shmid, void * shmAddr);


int iFnShmDt(int shmid);

int iFnShmDtProc(int shmid, unsigned int uiPid);
int iFnShmDtAllProc(unsigned int uiPid);

unsigned long ulFnMaxDirShmProc(unsigned int uiPid);

void vFnInicializarShms();
void vFnVerShm();




void vFnCopiarVariablesCompartidas();



void vFnCopiarVariable(void * dest, void * src, size_t tamanio);
# 9 "../include/kernel/pcb.h" 2
# 1 "../include/kernel/tiempo.h" 1
# 53 "../include/kernel/tiempo.h"
typedef unsigned long int time_t;
typedef unsigned long int clock_t;





typedef struct{

        clock_t tms_utime;


        clock_t tms_stime;


        clock_t tms_cutime;


        clock_t tms_cstime;
} tms;





typedef struct{

        int tz_minuteswest;


        int tz_dsttime;
} timezone;





typedef struct{

        unsigned long int tv_sec;


        unsigned long int tv_usec;
} timeval;





typedef struct{

        timeval it_interval;


        timeval it_value;
} itimerval;





typedef struct{

        int modes;


 long offset;


 long freq;


 long maxerror;


 long esterror;


 int status;


 long constant;


 long precision;


 long tolerance;


 timeval time;


 long tick;
} timex;





typedef struct{

        long int tv_sec;


        long int tv_nsec;
} timespec;
# 10 "../include/kernel/pcb.h" 2
# 27 "../include/kernel/pcb.h"
typedef struct {
 unsigned char ident[16];
 unsigned short type;
 unsigned short machine;
 unsigned int version;
 unsigned int entry;
 unsigned int phoff;
 unsigned int sphoff;
 unsigned int flags;
 unsigned short ehsize;
 unsigned short phentsize;
 unsigned short phnum;
 unsigned short shentsize;
 unsigned short shnum;
 unsigned short shstrndx;
} elfHeader;

typedef struct {
 unsigned int name;
 unsigned int type;
 unsigned int flags;
 unsigned int addr;
 unsigned int offset;
 unsigned int size;
 unsigned int link;
 unsigned int info;
 unsigned int addralign;
 unsigned int entsize;
}SHeader;

typedef struct {
        unsigned int type;
 unsigned int offset;
 unsigned int vaddr;
        unsigned int paddr;
        unsigned int filesz;
        unsigned int memsz;
        unsigned int flags;
        unsigned int align;
} PHeader;






typedef struct {
   elfHeader elfHeaderData;
   SHeader SHeaderData;
   PHeader PHeaderData;
   unsigned char ucbuffer[4];
} stuHeaderELF;





typedef struct {
   int iEstado;
   long int liTamanio;
} stuEsperarMemoria;
# 96 "../include/kernel/pcb.h"
typedef struct _stuPCB_{
  unsigned long int ulId;
  unsigned int uiIndiceGDT_CS;
  unsigned int uiIndiceGDT_DS;
  unsigned int uiIndiceGDT_TSS;
  unsigned int uiIndiceGDT_SS0;
  void (* vFnFuncion) ();

  unsigned long ulParentId;
  unsigned long ulUsuarioId;
  int iPrioridad;
  int iEstado;
  unsigned long lNHijos;
  int iExitStatus;
  unsigned long ulLugarTSS;
  char stNombre[25];
  unsigned int uiTamProc;
  struct stuTablaPagina * pstuTablaPaginacion;
  unsigned int uiDirBase,

        uiLimite;
  stuMemoriasAtachadas memoriasAtachadas[5];


  unsigned long ulTiempoEspera;
  unsigned long ulTiempoServicio;



  struct stuPCB* pstuPcbSiguiente;

  tms stuTmsTiemposProceso;

  itimerval timers[3];

  long lNanosleep;

  unsigned int *puRestoDelNanosleep;

    long lPidTracer;

    unsigned int uiTamanioTexto;
    unsigned int uiTamanioDatosInicializados;
    unsigned int uiTamanioStack;

    unsigned int uiTamanioOverhead;

    unsigned int uiEsperaTeclado;

    stuHeaderELF stuCabeceraELF;
    int iModoParticion;
    stuEsperarMemoria stuEsperaMemoria;
    unsigned int uiBaseSs0;
}stuPCB;
# 3 "main.c" 2
# 1 "../include/kernel/gdt.h" 1
# 32 "../include/kernel/gdt.h"
stuPCB pstuPCB[50];

int iCOLA_FLOPPY_ES[50];

unsigned int uiCOLA_FLOPPY_ES_INDEX_INI;
unsigned int uiCOLA_FLOPPY_ES_INDEX_FIN;
unsigned int uiPROC_FLOPPY;
unsigned int uiFIN_FLOPPY;
unsigned int uiCiclo;

unsigned int uiTamHeap;
# 63 "../include/kernel/gdt.h"
typedef struct {
  unsigned short usLimiteBajo;
  unsigned short usBaseBajo;
  unsigned char ucBaseMedio;







 unsigned char ucAcesso;

  unsigned int bitLimiteAlto:4;
# 89 "../include/kernel/gdt.h"
 unsigned int bitGranularidad:4;

  unsigned char usBaseAlto;

} __attribute__((packed)) stuGDTDescriptor;






typedef struct {
   stuGDTDescriptor stuGdtDescriptorDescs[8192];
} stuEstructuraGdt;



stuEstructuraGdt *pstuTablaGdt;






typedef struct {
  unsigned int control;
  unsigned int status;
  unsigned int tag;
  unsigned int ip;
  unsigned int cs;
  unsigned int dp;
  unsigned int ds;
  u80 st[8];
} __attribute__((packed)) stuFpu;
# 131 "../include/kernel/gdt.h"
typedef struct {
  unsigned int uiEnlace;
  unsigned int esp0;
  unsigned int ss0;
  unsigned int esp1;
  unsigned int ss1;
  unsigned int esp2;
  unsigned int ss2;
  unsigned int cr3;
  unsigned int eip;
  unsigned int uiEBandera;
  unsigned int eax;
  unsigned int ecx;
  unsigned int edx;
  unsigned int ebx;
  unsigned int esp;
  unsigned int ebp;
  unsigned int esi;
  unsigned int edi;
  unsigned int es;
  unsigned int cs;
  unsigned int ss;
  unsigned int ds;
  unsigned int fs;
  unsigned int gs;
  unsigned int ldt;
  unsigned int trapbit;
  unsigned int uIOMapeoBase;
  char espacio0[1024];
  char espacio1[16];
  char espacio2[16];
  stuFpu fpu;
}stuTSS;


typedef struct {
    void * pvPuntoCarga;
    unsigned int uiTamanioTexto;
    unsigned int uiTamanioDatosInicializados;
    unsigned int uiTamanioStack;
    char stNombre [13];
} stuInfoEjecutable;







stuPCB pstuPCB[50];
stuTSS stuTSSTablaTareas[50];





typedef struct {
   char stBinario[30];
   long int liTamanio;
} stuListaEspera;


int iCantEnEspera;
stuListaEspera stListaEspera[100];
void vFnGdtInicializar(dword);

int iFnBuscaPosicionProc(unsigned long);
unsigned int uiFnSetearBaseLimiteDescriptor(int,unsigned int,unsigned int);

unsigned int iFnAgregarDescriptorGDT(unsigned int,unsigned int,unsigned int,int);

int iFnBuscarPCBLibre();
unsigned int uiFnBuscarEntradaGDTLibre();

void vFnRecorrerListaEspera();
int iFnCrearTSSReloj (void*,int,unsigned int,unsigned int,unsigned int);
int iFnCrearTSS (void*,void*,int,unsigned int,unsigned int,unsigned int,unsigned int,unsigned int,int);

int iFnCrearPCB(int,void*,char*,unsigned int,unsigned int,unsigned int,unsigned int,unsigned int,unsigned int,unsigned int,unsigned int, unsigned int, unsigned int,unsigned int);

int iFnInstanciarReloj(void *, char*);
int iFnInstanciarIdle();
int iFnInstanciarInit();

void vFnAgregarListaEspera(char*, long int);

int iFnLeerCabeceraEjecutable(char* stArchivo, stuInfoEjecutable* pstuInfo);

int iFnCrearProceso(char *,int,int);
int iFnCrearCallGate(int, unsigned short, unsigned short, unsigned char, unsigned int, unsigned int, unsigned short);
int iFnRedimensionarProceso(unsigned long ulPid, unsigned long ulBrk);

int iFnDuplicarProceso(unsigned int uiProcPadre);
int iFnEliminarProceso(unsigned int uiProcesp);
int iFnReemplazarProcesoFija( unsigned int uiProceso, unsigned char *__codigo, unsigned int size );
int iFnReemplazarProceso(unsigned long, char *, unsigned int);






char* pstFnObtenerEnviroment();


int iFnClonarProceso();
# 4 "main.c" 2
# 1 "../include/kernel/sched.h" 1
# 15 "../include/kernel/sched.h"
typedef struct
{
 int sched_priority;
}sched_param;


unsigned long int uliTimeSlice;


unsigned long int uliQuantum;

unsigned long int uliBTSQ;


static int staiN = 0;

static int staiProcesoAnterior = -1;


int iTareaNula;

void vFnPlanificadorFIFO();
void vFnPlanificadorRR();
void vFnPlanificadorBTS();
# 5 "main.c" 2

# 1 "../include/kernel/mem/mem_part_firstfit.h" 1
# 22 "../include/kernel/mem/mem_part_firstfit.h"
typedef struct {
        int piPorcentajesPartFija[100];
} t_Porcentaje;

typedef struct {
 int iUsado;
 long int liTam;
} t_Nodo;



void* ptrHeap;
t_Nodo* ptrActual;
long int liHeapEnd;
int iModo;
int iKernel;
int iModoFijo;

long int piDistribucionPartFija[100];
long int piPorcentajesPartFija[100];

long int liTamanioLiberado;
long int liTamHeap;
long int liTamFija;
long int liTamHeapFijoVariable;

void vFnCrearNodo(long int, int, long int);
int iInicializar();
void* pvFnMalloc(long int);
void* pvFnRealloc(long int, unsigned long);
int iFnFree(long int);
# 7 "main.c" 2
# 1 "../include/kernel/mem/mem_part_kernel.h" 1



void* ptrHeapBajoKernel;
long int liTamanioHeapBajoKernel;

void* ptrHeapAltoUsuario;
long int liTamanioHeapAltoUsuario;


long int liTamFijaMemBaja;
long int liTamFijaMemAlta;
long int liTamanioSolicitado;

int iModoMemoriaKernel;
char stTamanioMemFija[20];
int iTamanioMemFijaSeteado;
int iPosicionSetMemFija;
int iContinuar;
int iModoFijoUser;

void vFnInicializarHeapsKernel();
void vFnConfigurarParticiones();

void * pvFnReservarParticionUsuario(unsigned int);
void * pvFnReservarParticionKernel(unsigned int);
void * pvFnRedimensionarSegmento(void*, unsigned long);
void vFnLiberarParticion( void * );
unsigned int uiHeapKernelInicializado;
unsigned int uiKernelStack;
# 8 "main.c" 2
# 1 "../include/kernel/mem/paginas.h" 1
# 13 "../include/kernel/mem/paginas.h"
struct stuTablaPagina{
  unsigned int uiFrame;
  unsigned int bUsado;
  };





struct stuBitMap {
  unsigned bit0: 1,
    bit1: 1,
    bit2: 1,
    bit3: 1,
    bit4: 1,
    bit5: 1,
    bit6: 1,
    bit7: 1;
  }__attribute__((packed));


int iTamanioMemoria;
int iLimCantPaginasProceso;


struct stuTablaPagina* pstuTablaPaginaFnAsignarPaginas (unsigned int);

void vFnIniciarMapaBits(int , int);




int iFnBuscarVacio();




int iFnVerificarSuficientes(int);

void vFnLimpiarFrame(int);




int iFnLimpiarMemoria(int, struct stuTablaPagina *);

void vFnImprimirTablaPaginas(int, struct stuTablaPagina *);

void vFnImprimirMapaBits();

int iFnDarDireccion( struct stuTablaPagina *, int, int, int);
# 9 "main.c" 2
# 1 "../include/kernel/system_asm.h" 1
# 10 "../include/kernel/system_asm.h"
void vFnIniciarIDT_Asm(const word wLimit, const void *pvBase);
void vFnRemapearPIC_Asm();
void vFnIniciarTimer_Asm();
void vFnHandlerGenerico_Asm();
void vFnHandlerTimer_Asm();
void vFnHandlerTeclado_Asm();
void vFnExcepcionCPU7_Asm();
void vFnExcepcionCPU13_Asm();
void vFnExcepcionCPU16_Asm();
void vFnHandlerSyscall_Asm();
void vFnHandlerCallgate_Asm();
void vFnHandlerDisquette_Asm();
# 10 "main.c" 2
# 1 "../include/kernel/syscall.h" 1







# 1 "../include/kernel/signal.h" 1
# 9 "../include/kernel/syscall.h" 2
# 1 "../include/kernel/semaforo.h" 1
# 20 "../include/kernel/semaforo.h"
typedef struct
{
 int inicializado;
 int valor;
 unsigned long int head;
 unsigned long int tail;

 unsigned long int procesosEnCola;

 unsigned long int cola[5];
 unsigned long int pshared;
}semaforo;





typedef struct
{
 int sem_id;
}sem_t;





typedef struct{
 int pshared;
 unsigned int value;
} sem_init_params;


void vFnEncolarProceso(semaforo *sem, unsigned long int uliId);


void vFnInicializaCola(unsigned long int *cola);


int iFnHayProcesoEnEspera(semaforo *sem);


unsigned long int uliFnDesencolarProceso(semaforo *sem);


void vFnInicializarSemaforos();
# 77 "../include/kernel/semaforo.h"
int iFnSemInit(sem_t *sem, int pshared, unsigned int value);
# 86 "../include/kernel/semaforo.h"
int iFnSemClose(sem_t *sem);
# 106 "../include/kernel/semaforo.h"
int iFnSemWait(sem_t *sem);
# 116 "../include/kernel/semaforo.h"
int iFnSemPost(sem_t *sem);

int validaExistenciaSemaforo(sem_t *sem);


int agregarSemaforoAlSistema(int pshared, unsigned int value);

void vFnVerSemaforos();
# 10 "../include/kernel/syscall.h" 2
# 195 "../include/kernel/syscall.h"
enum __ptrace_request {
 PTRACE_TRACEME,
 PTRACE_PEEKTEXT,
 PTRACE_PEEKDATA,
 PTRACE_PEEKUSER,
 PTRACE_POKETEXT,
 PTRACE_POKEDATA,
 PTRACE_POKEUSER,
 PTRACE_GETREGS,
 PTRACE_GETFPREGS,
 PTRACE_SETREGS,
 PTRACE_SETFPREGS,
 PTRACE_CONT,
 PTRACE_KILL,
 PTRACE_ATTACH,
 PTRACE_DETACH
};


typedef struct {
 int iPid;
 void *pvAddr;
 void *pvData;
}__ptrace_param;



typedef struct _stuRegs_
{
  long ebx;
  long ecx;
  long edx;
  long esi;
  long edi;
  long ebp;
  long eax;
  int xds;
  int xes;
  long orig_eax;
  long eip;
  int xcs;
  long eflags;
  long esp;
  int xss;
} stuRegs;






long lFnSysExit( int status );
long lFnSysFork();
long lFnSysTest( long num );
long lFnSysRead( int, void *buf, size_t count );
long lFnSysWrite( int, const void *buf, size_t count );
long lFnSysWaitPid( int pid, int *status, int options );
long lFnSysExecve( const char *filename, char *argv[], char *envp[] );
long lFnSysTime( long *t );
long lFnSysGetPid();
long lFnSysKill( int pid, int sig );
long lFnSysGetPPid();
long lFnSysReboot( int flag );
long lFnSysSodiumCallgate(int iOpcion, int iPar1, int iPar2);
long lFnSysBrk(unsigned long);
long lFnSysSBrk(unsigned long);
long lFnSysSemInit( sem_t *sem, sem_init_params * params);
long lFnSysSemPost( sem_t *sem );
long lFnSysSemWait( sem_t *sem );
long lFnSysSemClose( sem_t *sem );
long lFnSysShmGet( key_t key, size_t size );
long lFnSysShmAt( int shmid, void * shmAddr );
long lFnSysShmDt( key_t key );

int iFnSysSumar(int a, int b, int * res);



long lFnSysNice( int );
long lFnSysGetpriority( int, int );
long lFnSysSetpriority( int, int, int );
long lFnSysClone(stuRegs *,int flags);


long lFnSysIdle();



long lFnSysSchedSetParam(int p);
long lFnSysSchedGetParam();
long lFnSysSchedSetScheduler(int p);
long lFnSysSchedGetScheduler();
long lFnSysSchedYield();
long lFnSysSchedGetPriorityMax();
long lFnSysSchedGetPriorityMin();
long lFnSysSchedRrGetInterval();





long lFnSysStime(time_t *newtime);
long lFnSysTimes(tms *ptmsbuffer);
long lFnSysGettimeofday(timeval *ptimervalTp, timezone *ptimezoneTzp);
long lFnSysSettimeofday(timeval *ptimevalTp, timezone *ptimezoneTzp);
long lFnSysGettimer(int iWhich, itimerval *pitimervalValue);
long lFnSysSettimer(int iWhich, itimerval const *pcnitimervalValue, itimerval *ptimervalOvalue);
long lFnSysAdjtimex(timex *ptimexBuffer);
long lFnSysNanosleep(timespec const *pcntimespecRequested_time, timespec *ptimespecRemaining);



long lFnSysPtrace( int request, void *pvDirParam );





unsigned long ulFnSysBrk(unsigned long brk);
# 11 "main.c" 2
# 1 "../include/kernel/system.h" 1
# 22 "../include/kernel/system.h"
unsigned long int uliClockTick;





typedef struct
{
    unsigned int :16;
    unsigned int TSSSegmentSelector :16;
    unsigned int :8 ;
    unsigned int Type :5;
    unsigned int DPL :2;
    unsigned int P :1;
    unsigned int :16;
} __attribute__((packed)) t_TaskGate;





typedef struct
{
    unsigned int Offset1 :16;
    unsigned int SegmentSelector :16;
    unsigned int :5 ;
    unsigned int Type :8;
    unsigned int DPL :2;
    unsigned int P :1;
    unsigned int Offset2 :16;
} __attribute__((packed)) t_InterruptGate;




typedef struct
{
    unsigned int Offset1 :16;
    unsigned int SegmentSelector :16;
    unsigned int :5 ;
    unsigned int Type :8;
    unsigned int DPL :2;
    unsigned int P :1;
    unsigned int Offset2 :16;
} __attribute__((packed)) t_TrapGate;




typedef union
{
    t_TaskGate TaskGate;
    t_InterruptGate InterruptGate;
    t_TrapGate TrapGate;
}stuIDTDescriptor;




typedef struct
{
    stuIDTDescriptor IDTDescriptor[256];
} stuIDT;


typedef struct
{
    dword dwLimite :16;
    dword dwBase :32;
} t_IDTRegister;

stuIDT *pstuIDT;
unsigned char ucFnObtenerScanCode();
void vFnIniciarTeclado();
void vFnIniciarExcepciones();
void vFnIniciarIDT();
void vFnHandlerGenerico();
void vFnHandlerTimer();
void vFnPlanificador();
void vFnHandlerTeclado();
void* pvFnKernelStackAdmin();


void vFnHandlerDisquette();

long vFnHandlerSyscall( long eax,
   long ebx,
   long ecx,
   long edx );

void vFnLTR(unsigned int uiSelector);
unsigned int uiFnSTR(void);
# 12 "main.c" 2
# 1 "../include/shell/shell.h" 1
# 13 "../include/shell/shell.h"
void vFnManejadorTecladoShell(unsigned char scanCode);

char cFnGetch();
char cFnPausa();
int iFnGetArg(int iPos, int iNumero, char* stResultado, int iAnchoMaximo);
int iFnXtoI (char *c);
int iFnHtoI (char *c);

void vFnAPM_info();
void vFnAPM_shutdown();

void vFnLoopReloj();
void vFnImprimirMenu ();
void vFnImprimirContexto();
void vFnMenuInstanciarInit();
void vFnMostrarListaParticiones();
void vFnBorrarUltimaPartFija();
void vFnAgregarPartFija(char*);
void vFnResetearListaPart();
int iFnShellActivo();


void vFnImprimirMenu ();
void vFnImprimirSeparadores ();




void vFnShell ();
void vFnMenuAyuda ();



void vFnMenuDump (int,int);
void vFnMenuWriteArch(int,int);
void vFnMenuOptKill(int);
void iFnTomaPrimerPara();
void iFnTomaNParametro(int,char *);
void vFnConvierteACadena(int, char *);



void vFnMenuKill (int);
void vFnMenuKillSeg (int);
void vFnMenuMem ();
void vFnMenuVer ();
void vFnMenuDesc (int,int);
void vFnMenuEjecutar(int);
void vFnMenuStack (int,int);
void vFnMenuGdt ();
void vFnMenuIdt ();
void vFnMenuCambiaTeclado (int);
void vFnMenuCls ();
void vFnMenuTSS (int);
void vFnMenuBitmap ();
void vFnMenuSegs ();
void vFnMenuPag (int);
void vFnMenuPs ();
void vFnMenuExec (int,int);
void vFnMenuExecSeg (int,int);
void vFnMenuLeerArch(int);
void vFnMenuCheck (int);
void vFnMenuSet (int);
void vFnSumaFpu (int);
void vFnMenuSumaFpu(int,int);
void vFnMenuVerSemaforos();
void vFnMenuVerShm();
void vFnMenuTestptrace(int);
void vFnMenuFd ();
void vFnMenuLs (int);
void vFnMenuCD(int);
void vFnMenuRm(int);

void vFnTermLog (unsigned char ucCaracter);

char *cpFnGetEnv(char *cpVariable);
void vFnGetAllEnv();
void vFnSetEnv(char *cpVariable, char *cpValor);
void vFnUnSetEnv(char *cpVariable);



typedef struct {
 char cpVariable[32 +1];
 char cpValor[32 +1];
 int iActiva;
}stuENV;




void vFnInicializarEnv();

stuENV pstuENV[10];


unsigned long ulPidProcesoForeground;
unsigned long uiAPM_ok;
unsigned long uiAPM_check_ax;
unsigned long uiAPM_check_bx;
unsigned long uiAPM_check_cx;

unsigned long uiAPM_32_cs;
unsigned long uiAPM_offset_entry_point;
unsigned long uiAPM_16_cs;
unsigned long uiAPM_ds;
# 13 "main.c" 2
# 1 "../include/shell/teclado.h" 1
# 509 "../include/shell/teclado.h"
char stBufferShell[256];

char stBufferTeclado[10];






struct _stuKeyCode {
    unsigned char tipo;
    unsigned char ascii;
};

typedef struct _stuKeyCode stuKeyCode;




struct _stuDefinicionTeclado {
    char sCodigo [5];
    char sNombre [25];
    stuKeyCode stashMatrizNormal [128];
    stuKeyCode stashMatrizShifted [128];
    stuKeyCode stashMatrizAltGred [128];
} __attribute__((packed));

typedef struct _stuDefinicionTeclado stuDefinicionTeclado;


void vFnManejadorTecladoShell (unsigned char ucScanCode);
void vFnScanCodeAKeyCode( stuKeyCode*, unsigned char );
void vFnScanCodeExtAKeyCode( stuKeyCode*, unsigned char );
void vFnKeyCodeNumPad( stuKeyCode* );
int iFnTeclaEspecial ( stuKeyCode, unsigned char );
int iFnCombinacionTeclasEspecial( stuKeyCode );
void * pvFnAbrirArchivoKeymap (void);
int iFnCambiaTecladoI(unsigned int);
int iFnCambiaTecladoS(char *);
void vFnListarKeymaps();
char cFnGetChar();
char cFnPausa();

int iCantidadCaracteres;
int iSemaforoBufferTeclado;
int iLlenarIndice;
static int staiVaciarIndice;
# 14 "main.c" 2
# 1 "../include/usr/reloj.h" 1
# 12 "../include/usr/reloj.h"
void vFnLoopReloj();

void vFnInicializarReloj();
# 15 "main.c" 2

# 1 "../include/fs/ramfs.h" 1
# 30 "../include/fs/ramfs.h"
typedef struct {
 char strNombreArchivo[11];
 word wSeg;
 word wOff;
 dword dwTamanio;
} __attribute__((packed)) stEntradaLS;




typedef struct {
 stEntradaLS stEnt[20];
} __attribute__((packed)) stDirectorio;




typedef struct {
 char strEtiqueta[20];
 char strPMontaje[44];
 dword dwDireccionInicial;
 dword dwTamanio;
 stDirectorio *pstDirRaiz;
 dword dwEntradasRaiz;
 u8 bActivo;
} stDiscoRAM;

int iFnRamFsInit(void);

int iFnNormalizarNomArch(const char *strNomArch83, char *strNomArch);

int iFnBuscarArchivo(stDirectorio * pstDir, char *strNombreArchivo, stEntradaLS ** ppstEntradaLSArchEnc);

int iFnObtenerDirectorio(char *strPMontaje, stDirectorio ** ppstDir);

int iFnObtenerDisco(char *strPMontaje, stDiscoRAM **ppstDisco);

int iFnRamFsLs(char *strParams);
# 17 "main.c" 2
# 1 "../include/kernel/drivers/dma.h" 1
# 89 "../include/kernel/drivers/dma.h"
void inicDMA();
void setCanalDMA(u8 Canal, u32 Direccion, u8 Modo, u16 Cuenta);
void setMascaraDMA(u8 Mascara);
void setDirDMA(u8 Canal, u32 Direccion);
void setContDMA(u8 Canal, u16 Cuenta);
void setModoDMA(u8 Modo);
void habilitarCanal(u8 Canal);
void inhibirCanal(u8 Canal);
u8 peticionDMA(u8 Canal);
u8 TCDMA(u8 Canal);
# 18 "main.c" 2
# 1 "../include/kernel/drivers/floppy.h" 1
# 19 "../include/kernel/drivers/floppy.h"
typedef struct {u8 RST0; u8 Valido;} ST0_t;
typedef struct {u8 RST1; u8 Valido;} ST1_t;
typedef struct {u8 RST2; u8 Valido;} ST2_t;




typedef struct
{
 u8 Cilindro;
 u8 Cabeza;
 u8 Sector;
}
CHS;




typedef enum
{
 Termin_Normal, Term_Anormal, Com_No_Finalizado, Com_Invalido
}Estado;


void* pvBufferDmaFloppy;
byte byBufferDmaNoAlineadoFloppy[512*2];
void* alinearBufferFloppyDMA(void* Buffer, unsigned long ulTamanioTotal);

u8 leerSector (byte* Buffer, u16 NBloque);
u8 escribirSector (byte* Buffer, u16 NBloque);
u8 operExitosa ();
void prenderMotor ();
void apagarMotor ();
u8 envComRecalibrado ();
u8 envComDesplCabeza (u8 Cilindro, u8 Cabeza);
u8 envComLectura (u8 Cilindro, u8 Cabeza, u8 Sector);
u8 envComEscritura (u8 Cilindro, u8 Cabeza, u8 Sector);
void enviarDatosOper (u8 Cilindro, u8 Cabeza, u8 Sector);
u8 leerEstadoFDC ();
void leerST0 ();
u8 leerST3 ();
u8 vFnImprimirST0 ();
void vFnImprimirST1 ();
void vFnImprimirST2 ();
void vFnImprimirST3 ();
void vFnImprimirEstadoFDC ();
u8 listoPES ();
u8 esperandoByteProc ();
u8 bytePProcesador ();
u8 FDCOcupado ();
u8 unidadOcupada ();
void obtResOper ();
void invalidarEstados ();
CHS LBAaCHS (u16 NBloque);

void ISRDisketeraC();
# 19 "main.c" 2

unsigned int uiTamanioMemoria;
unsigned int uiTamanioMemoriaBaja;
unsigned int uiTamanioMemoriaBios;
unsigned int uiUnidadBoot;
unsigned int uiTamanioBSS;
unsigned int uiTamanioKernel;
unsigned int uiModoMemoria;


unsigned int uiAPM_OK;

unsigned int uiAPM_CHECK_AX;
unsigned int uiAPM_CHECK_BX;
unsigned int uiAPM_CHECK_CX;

unsigned int uiAPM_32_CS;
unsigned int uiAPM_OFFSET_ENTRY_POINT;
unsigned int uiAPM_16_CS;
unsigned int uiAPM_DS;
extern stuPCB pstuPCB[50];

extern short int bPlanificador;
extern short int bActivarTeclado;



dword pdwGDT;




int iFmf, iCmf, iMatrizMf[30][2];
unsigned long ulMemoriaBase = 1048576;
unsigned long ulMemoriaTope = 6291456;



int iFnProcShell ();
int iFnSistema ();
int iFnProceso1 ();
int iFnProcReloj ();
void *pvFnFuncion;







int
main ()
{
  asm ("cli");
  uliClockTick = 0;

  uiHeapKernelInicializado = 0;
  uiKernelStack = 0x200000;
  if (uiModoMemoria == 2) iModo = 0;
  if (uiModoMemoria == 3) iModo = 1;
  vFnIniciarIDT ();
  vFnIniciarTeclado();
  bActivarTeclado = 1;
  vFnConfigurarParticiones();

  vFnImprimir ("\nBienvenidos al SODIUM...\n");

  vFnImprimir ("\nModelo de memoria elegido: ");
  if (uiModoMemoria == 1)
    vFnImprimir ("Paginado	");
  else
    vFnImprimir ("Segmentado	");


  vFnImprimir ("\nActivando Manejador del teclado ...         ");
  vFnImprimirOk (55);
  vFnImprimir ("\nIniciando IDT ...                           ");
  vFnImprimirOk (55);


  vFnImprimir ("\nIniciando los Manejadores de Excepciones ...");
  vFnIniciarExcepciones ();
  vFnImprimirOk (55);

  vFnImprimir ("\nIniciando GDT ...                           ");
  vFnGdtInicializar (pdwGDT);
  vFnImprimirOk (55);


  vFnImprimir ("\nInicializar Semaforos ...                   ");
  vFnInicializarSemaforos();
  vFnImprimirOk (55);

  vFnImprimir ("\nIniciando Dma ...                           ");
  inicDMA();
  vFnImprimirOk (55);

  vFnImprimir ("\nIniciando Administrador de Memoria ...                           ");
  vFnLog("\nTamanio de Heap de Usuario: 0x%x",100000);
  vFnImprimirOk (55);

  vFnImprimir ("\nIniciando el kernel heap ...                ");
  vFnInicializarHeapsKernel();
  uiHeapKernelInicializado=1;
  vFnImprimirOk (55);

  vFnImprimir ("\nCreando Stack de Kernel ...                ");
  uiKernelStack = (pvFnReservarParticionKernel(4096) + 4096 -4);
  vFnLog("\nPosicion del stack de kernel: 0x%x",uiKernelStack);
  vFnImprimirOk (55);

  vFnImprimir ("\nIniciando los discos RAM ...                ");
  vFnInicializarPath();

  if (iFnRamFsInit()==0)
   vFnImprimirOk (55);
  else
   vFnImprimirNOk(55);




  vFnImprimir ("\nIniciando Tablas de Memoria ...              ");

  if (uiModoMemoria == 1) vFnIniciarMapaBits (ulMemoriaBase, ulMemoriaTope);




  vFnImprimirOk (55);




  vFnImprimir ("\nActivando Planificador de tareas (RR) ...   ");
  lFnSysSchedSetScheduler(1);
  vFnImprimirOk (55);

  vFnImprimir ("\nSeteando parametros de planificador RR ...  ");
  lFnSysSchedSetParam(1);
  uliTimeSlice=0;
  vFnImprimirOk (55);


  vFnImprimir ("\nIniciando Tarea Nula ...                    ");
  iFnInstanciarIdle();
  vFnImprimirOk (55);

  vFnImprimir ("\nCreando callgate para servicios SODIUM ...  ");
  pvFnFuncion = (void *) vFnHandlerCallgate_Asm;
  iFnCrearCallGate(7,(int)pvFnFuncion & 0x0000FFFF, 0x08, 0x0, 0xC, 0xE0, 0x0);
  vFnImprimirOk (55);



  vFnImprimir ("\nInicializar Memoria Compartida...           ");
  vFnInicializarShms();
  vFnImprimirOk (55);



  vFnImprimir ("\nIniciando reloj del sistema ...          ");
  vFnInicializarReloj();
  vFnImprimirOk (55);

  iFnInstanciarReloj(vFnLoopReloj, "PR_Reloj............");
  vFnImprimir ("\nIniciando Proceso Reloj ...                 ");
  vFnImprimirOk (55);

  vFnImprimir ("\nIniciando Task Register ...                 ");
  vFnLTR ((unsigned int) pstuPCB[0].uiIndiceGDT_TSS * 8);
  vFnImprimirOk (55);

  vFnImprimir ("\nMemoria total del sistema: %d MB",
        uiTamanioMemoriaBios / 1024 / 1024);
  vFnImprimir ("\nHabilitando Interrupciones ...              ");
  vFnImprimirOk (55);

  vFnImprimir ("\nIniciando Proceso Shell ...                 ");
  vFnImprimirOk (55);

  iFnInstanciarProceso("SHELLUSR.BIN", 3, 0);
  iFnProcShell (0);



  uiAPM_ok = uiAPM_OK;

  uiAPM_check_ax = uiAPM_CHECK_AX;
  uiAPM_check_bx = uiAPM_CHECK_BX;
  uiAPM_check_cx = uiAPM_CHECK_CX;

  uiAPM_32_cs = uiAPM_32_CS;
  uiAPM_offset_entry_point = uiAPM_OFFSET_ENTRY_POINT;
  uiAPM_16_cs = uiAPM_16_CS;
  uiAPM_ds = uiAPM_DS;


  asm ("sti");


  while (1)
    {
    }

}







int
iFnSistema (int iPid)
{
# 246 "main.c"
  while (1);

  return (1);
}







int
iFnProceso1 (int iPid)
{
  unsigned long int uliTiempoAlarma = uliClockTick + 1;
  unsigned long int uliNroBucles = 0;
  int iPCB;

  iPCB=iFnBuscaPosicionProc(iPid);
  while (1)
    {
      if (uliClockTick > uliTiempoAlarma)
 {
   uliTiempoAlarma = uliClockTick + 1;

   vFnImprimirVentana (3,
         "\ngetpid(): %d, getppid(): %d, %s. ClockTicks=%d, MBucles.Seg=%d (aprox)",
         lFnSysGetPid(),
         lFnSysGetPPid(),
         pstuPCB[iPCB].stNombre,
         uliClockTick,
         (uliNroBucles * 18 + uliNroBucles / 10 * 2)/1000000);
   uliNroBucles = 0;
 }
      uliNroBucles++;
    }
  return (1);
}
# 317 "main.c"
int iFnProcShell (int iPid)
{
  if(iFnCambiaTecladoS("us") != 0)
     iFnCambiaTecladoI(1);

  vFnImprimirContexto ();


  return (1);
}
